package org.example.device.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * 设备控制配置类
 * 配置设备控制相关的Bean和参数
 */
@Configuration
public class DeviceControlConfig {
    
    /**
     * 配置RestTemplate用于HTTP协议通信
     */
    @Bean("deviceControlRestTemplate")
    public RestTemplate deviceControlRestTemplate() {
        return new RestTemplate();
    }
    
    /**
     * 设备控制配置参数
     */
    @Bean("deviceControlProperties")
    public Map<String, Object> deviceControlProperties() {
        Map<String, Object> config = new HashMap<>();
        
        // MQTT配置
        Map<String, Object> mqttConfig = new HashMap<>();
        mqttConfig.put("brokerUrl", "tcp://localhost:1883");
        mqttConfig.put("clientId", "smart-home-backend");
        mqttConfig.put("username", "admin");
        mqttConfig.put("password", "admin123");
        mqttConfig.put("keepAlive", 60);
        mqttConfig.put("cleanSession", true);
        config.put("mqtt", mqttConfig);
        
        // HTTP配置
        Map<String, Object> httpConfig = new HashMap<>();
        httpConfig.put("baseUrl", "http://localhost:8080/api");
        httpConfig.put("timeout", 5000);
        httpConfig.put("retryCount", 3);
        config.put("http", httpConfig);
        
        // WebSocket配置
        Map<String, Object> websocketConfig = new HashMap<>();
        websocketConfig.put("endpoint", "ws://localhost:8080/ws");
        websocketConfig.put("pingInterval", 30000);
        websocketConfig.put("reconnectInterval", 5000);
        config.put("websocket", websocketConfig);
        
        // CoAP配置
        Map<String, Object> coapConfig = new HashMap<>();
        coapConfig.put("serverUrl", "coap://localhost:5683");
        coapConfig.put("timeout", 5000);
        coapConfig.put("retryCount", 3);
        config.put("coap", coapConfig);
        
        // 设备控制通用配置
        Map<String, Object> controlConfig = new HashMap<>();
        controlConfig.put("defaultTimeout", 10000);
        controlConfig.put("maxRetryCount", 3);
        controlConfig.put("retryInterval", 1000);
        controlConfig.put("enableLogging", true);
        config.put("control", controlConfig);
        
        return config;
    }
}
